package ArrayAndString;

import java.util.ArrayList;
import java.util.List;

public class YangHuiTriangle_II {
    public static List<Integer> getRow(int rowIndex) {
        List<Integer> result = new ArrayList<>();
        int[][] nums = new int[rowIndex+1][rowIndex+1];
        for (int i = 0; i <=rowIndex; i++) {

            for (int j = 0; j <= i; j++) {
                if (j == 0 || i == j) {
                    nums[i][j] = 1;
                } else {
                    nums[i][j] = nums[i - 1][j - 1] + nums[i - 1][j];
                }
                if(i==rowIndex){
                    result.add(nums[i][j]);
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(getRow(4));
    }
}
